package com.android.job.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.job.model.Job;
import com.android.job.ui.R;

/**
 * 职位查询结果列表的Adapter
 * 
 * @author yyl
 * 
 */
public class JobItemAdapter extends BaseAdapter
{
	private Context mContext;
	private List<Job> jobList;
	private ViewHolder holder;

	public JobItemAdapter(Context mContext, ArrayList<Job> jobList)
	{
		super();
		this.mContext = mContext;
		this.jobList = jobList;
	}

	@Override
	public int getCount()
	{
		return jobList.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position;
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		if (convertView == null)
		{
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.job_item, null);
			holder.companyName = (TextView) convertView
					.findViewById(R.id.company_name);
			holder.job = (TextView) convertView
					.findViewById(R.id.job_description);
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.companyName.setText(jobList.get(position).getCompanyName());
		holder.job.setText(jobList.get(position).getPostName());
		
		return convertView;
	}

	private class ViewHolder
	{
		/**
		 * 公司名称
		 */
		private TextView companyName;

		private TextView job;

	}
}
